<script setup>
import { ref, watch } from 'vue'
const state = ref({
  name: '小敏'
})
// 单独监听对象中属性
watch(
  ()=>state.value.name,
  (newVal,oldVal)=>{
    console.log({newVal,oldVal})
  }
)
const changeName = ()=>{
  state.value.name = '小芳'
}
</script>
<template>
<div>
  {{state.name}}
  <button @click="changeName">点我</button>
</div>
</template>
<style scoped>
</style>